package mcom.xmks.bluetooth.mesh.utils;

public class ArrayConvert {

    public static byte[] reverse(byte[] source){
        if(source==null){
            return null;
        }
        byte[] newArray=new byte[source.length];
        for (int i = 0; i < source.length; i++) {
            newArray[i]=source[source.length-1-i];
        }
        return newArray;
    }

    public static byte[] fromIntegerLittleEnd(int source){

        byte[] newArray=new byte[4];
        newArray[0]= (byte) (source & 0x000000ff);
        newArray[1]= (byte) ((source & 0x0000ff00)>>8);
        newArray[2]= (byte) ((source & 0x00ff0000)>>16);
        newArray[3]= (byte) ((source & 0xff000000)>>24);

        return newArray;
    }

    public static int toIntegerLittleEnd(byte[] source){

        return source[0] & 0x000000ff | (source[1] & 0x000000ff)<<8 | (source[2] & 0x000000ff)<<16 | (source[3] & 0x000000ff)<<24;
    }




}
